#!/usr/bin/expect
#beetle机器能否正常访问svn

set timeout 1
set svnUserName [lindex $argv 0]
set svn_path [lindex $argv 1]
set svn_pass [lindex $argv 2]
set user [lindex $argv 3]
#开启子进程
spawn su ${user}
expect "*$*"
send "cd \r"
expect "*$*"
send "svn log ${svn_path} --username ${svnUserName}\r"
expect {
    "*ermanently*" {
        send "p\r"
        expect {
            "*assword*" {
                send "${svn_pass}\r"
                expect {
                    "*yes/no*" {
                        send "yes\r"
                        expect eof
                    }
                    "*sername*" {
                        exit 1
                    }
                }
            }
        }
    }
    "*assword*" {
        send "${svn_pass}\r"
        expect {
            "*yes/no*" {
                send "yes\r"
                expect eof
            }
            "*sername*" {
                exit 1
            }
        }
    }
    "*E000111*" {
        exit 1
    }
    "*E670002*" {
        exit 1
    }
}
expect eof
exit
